import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login/Login.vue'
import Home from '../views/Home/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../views/Home/Users/Users.vue'
import Rights from '../views/Home/Power/Rights.vue'
import Roles from '../views/Home/Power/Roles.vue'
import Cate from '../views/Home/Goods/Cate/Cate.vue'
import Params from '../views/Home/Goods/Params/Params.vue'
import GoodList from '../views/Home/Goods/List/List.vue'
import AddList from '../views/Home/Goods/List/AddList/AddList.vue'
import Order from '../views/Home/Order/Order.vue'
import Report from '../views/Home/Report/Report.vue'
Vue.use(VueRouter)


const router = new VueRouter({
  routes: [
    {path:'/',redirect:'/login'},
    {path:'/login',component:Login},
    {path:'/home',
    component:Home,
    redirect:'/home/welcome',
    children:[
      {
        path:'welcome',
        component:Welcome
      },
      {
        path:'/home/users',
        query:{
          oneTitle:666,
          twoTitle:'你好'
          },
        component:Users
      },
      {
        path:'/home/rights',
        component:Rights
      },
      {
        path:'/home/roles',
        component:Roles
      },
      {
        path:'/home/categories',
        component:Cate
      },
      {
        path:'/home/params',
        component:Params
      },
      {
        path:'/home/goods',
        component:GoodList,
      },
      {
        path:'/home/goods/add',
        component:AddList,
      },
      {
        path:'/home/orders',
        component:Order,
      },
      {
        path:'/home/reports',
        component:Report,
      },
    ]
  },

   ]
})
//挂载路由导航守卫
router.beforeEach((to, from, next)=>{
//to表示将要访问的路径
//from代表从哪个路径跳转而来
//next 是一个函数，表示放行
//next()放行 next（'login'）强制跳转
if(to.path ==='/login') return next()
const tokenStr = window.sessionStorage.getItem('token')
if(!tokenStr) return next('/login')
next()
})

export default router
